<!DOCTYPE html>
<meta charset="UTF-8">
<div class="input-group" style="width: 287px;">
	<span class="input-group-addon" style="width: 80px;">选择租户</span> <select
		onchange="mChange(this.value)" id="mSel" class="form-control">
		<option th:each="l:${lessees}" th:value="${l.id}"
			th:text="${l.tenantname}"></option>
	</select>
</div>
<script type="text/javascript">
var options = {
		url : '../enduser/list',
		editurl : '../enduser/edit',
		caption : '用户管理',
		//显示数据数
		viewrecords : true,
		altRows : true,
		autowidth : true,
		width : 1000,
		height : 'auto',
		datatype : 'json',
		mtype : 'post',
		rowNum : 10,
	    postData:{lesseeId:[[${lesseeid}]]},
		rowList : [ 10, 20, 50 ],
		prmNames : {
			search : "search"
		},
		sortname : 'id',
		viewrecords : true,
		pager : '#div1',
		jsonReader : {
			repeatitems : false,
			id : 'id'
		},
		colModel : [
		{
			label : '序号',
			name : 'id',
			index : 'id',
			align : 'center',
			sortable : true,
			width : 50,
			sorttype : 'int',
			search : false,
			hidden:true
		}, {
			label : '姓名',
			name : 'name',
			index : 'name',
			align:'center',
			sortable:true,
			width:80,
			sorttype:'int',
			search:true, //查询
			editable : true,
			editrules : {
				edithidden : true,
				required:true
				}
		}, {
			label : '登录名',
			name : 'username',
			index : 'username',
			align : 'center',
			sortable : true,
			width : 80,
			sorttype : 'int',
			search:true,
			editable : true,
			editrules : {
				edithidden : true,
				required:true
				}
		}, {
			label : '备注',
			name : 'remark',
			index : 'remark',
			align : 'center',
			sortable : true,
			width : 80,
			sorttype : 'int',
			search : true,
			editable : true
		},{
			label : '管理员',
			name : 'lessee.id',
			index : 'lessee.id',
			hidden:true,
			align:'center',
			sortable:true,
			width:50,
			sorttype:'int',
			search:false,
			editable:false
		},{
			label:'操作',
			name:'id',
			index:'id',
			align:'center',
			width:50,
			edittype:"button",
			formatter:cmgStateFormat,
			search:false
	}]
	}
	$(function() {
		$('#tabel1').jqGrid(options);
		$("#tabel1").jqGrid('navGrid','#div1',{
					edit :true,
					add : true,
					del : true,
					view:true
				},{
					//改
					top:200,
					left:600,
					beforeSubmit : function(postdata, formid) {
						postdata['lessee.id'] = $('#mSel')
						.val();
						return [ true, 'OK!' ];
					},
					closeAfterEdit : true,
					closeOnEscape : true,
					savekey : [ true, 13 ]
				},{
					//增
					top:200,
					left:600,
					beforeSubmit : function(postdata, formid) {
						postdata.id = '',
								postdata['lessee.id'] = $('#mSel')
										.val();
						return [ true, 'OK!' ];
					},
					closeAfterAdd : true,
					closeOnEscape : true,
					savekey : [ true, 13 ]
				},{
					//删
					top:200,
					left:600
				},{
					//查
					top:200,
					left:600,
					sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'bw', 'bn', 'in', 'ni', 'ew', 'en', 'cn', 'nc'],
					multipleSearch:true,
					closeAfterSearch : true,
					closeAftreReset : true,
					closeOnEscape : true,
					multipleSearch : true
				});
	});
	function mChange(lesseeId) {
		var postdata = {
			lesseeId : lesseeId
		};
		options.postData = postdata;
		$("#tabel1").setGridParam(options).trigger("reloadGrid");
	}
	
	function cmgStateFormat(cellValue) {
		return "<button class='btn btn-info	 ' onclick=\"change("
				+ cellValue + ")\">重置密码</button>";
	}

	function change(id) {
		if (confirm('确定要重置密码？')) {
			$.ajaxSettings.async = false;
			$.post("enduser/changepwd?id=" + id, function(r) {	
					alert(r)		
			});
			$.ajaxSettings.async = true;
		}
	}
</script>
<table id="tabel1"></table>
<div id="div1"></div>